import { ref } from "vue";

export default function InitHook() {
  const loading = ref<boolean>(false);
  const tableData = ref<Array<CustomerServiceWaybill.ListRows>>([]);
  const conifg = {
    beforeChange: (changes: any) => {
      // [[row, prop, oldVal, newVal], ...]
      for (let i = 0; i < changes.length; i++) {
        const target = changes[i];
        if (["pickingBoxLength", "pickingBoxWidth", "pickingBoxHeight", "pickingBoxWeight"].includes(target[1])) {
          if (changes[i][3].length > 5) {
            changes[i][3] = changes[i][3].slice(0, 5);
          }
          if (isNaN(Number(target[3]))) {
            changes[i][3] = 0;
          } else {
            changes[i][3] = Number(changes[i][3]).toFixed(2);
          }
        }
      }
    }
  };
  return {
    loading,
    tableData,
    conifg
  };
}
